#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
#include <algorithm>
#include <cstring>
using namespace std;
#define DEBUG
using ll=long long;
const int N=500010, M=N<<1;
int n, m;
struct Data
{
    int x, y, z, p, id, sign; //(x, y)坐标 基站0/查询1 功率 查询id 符号标识(计算查询区域的功率总和)
    ll sum; //临时存储功率总和
    bool operator<(const Data& t) const
    {
        if(x!=t.x) return x<t.x;
        if(y!=t.y) return y<t.y;
        return z<t.z;
    }

    bool operator==(const Data& t) const
    {
        return x==t.x && y==t.y && z==t.z;
    }
}q[N], w[N];
ll ans[N];

void merge_sort(int l, int r)
{
    if(l>=r) return;
    int mid=l+r>>1;
    merge_sort(l, mid); merge_sort(mid+1, r);

    int i=l, j=mid+1, k=0;
    ll sum=0;
    while(i<=mid&&j<=r)
        if(q[i].y<=q[j].y) sum+=!q[i].z*q[i].p, w[k++]=q[i++]; //左半区间y更小，符合区域条件
        else q[j].sum+=sum, w[k++]=q[j++]; //左半区间y更大，将y小的区域的权值和加至当前区域
    while(i<=mid) sum+=!q[i].z*q[i].p, w[k++]=q[i++]; //左半区域未被访问的点加至末尾
    while(j<=r) q[j].sum+=sum, w[k++]=q[j++]; //右半区域未被访问的点加至末尾
    for(i=l, j=0; j<k; i++, j++) q[i]=w[j]; //写回
}

void init()
{
    read(n), read(m);
    for(int i=0; i<n; i++)
    {
        int x, y, p; read(x), read(y), read(p);
        q[i]={x, y, 0, p};
    }
}

void solve()
{
    init();
    int k=n;
    for(int i=1; i<=m; i++)
    {
        int x1, x2, y1, y2;
        read(x1), read(y1), read(x2), read(y2);
        q[k++]={x2, y2, 1, 0, i, 1};
        q[k++]={x1-1, y2, 1, 0, i, -1};
        q[k++]={x2, y1-1, 1, 0, i, -1};
        q[k++]={x1-1, y1-1, 1, 0, i, 1};
    }
    sort(q, q+k);
    merge_sort(0, k-1);

    for(int i=0; i<k; i++)
        if(q[i].z)
            ans[q[i].id]+=q[i].sum*q[i].sign;
    for(int i=1; i<=m; i++) quickwrite(ans[i]), puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        freopen("./out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
